﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaiTu.Common.Helpers
{
    public class CheckIsNullHelper<T> : Framework.Interfaces.ISingletonDependency
        where T : class
    {
        /// <summary>
        /// 检测一个对象是否是Null
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static bool CheckIsNull( T t)
        {
            bool flag = false;
            if (t != null)
            {
                flag = false;
            }
            else
            {
                flag = true;
            }
            return flag;
        }
        /// <summary>
        /// 判断为Null 抛出异常信息
        /// </summary>
        /// <param name="t"></param>
        public static void CheckIsNullThrowException( T t)
        {
            if (t == null)
            {
                throw new Framework.Exceptions.BaiTuCoreException("对象为Null");
            }
        }

        /// <summary>
        /// 检测是否为Null或Empty 其中Empty只针对字符串类型
        /// </summary>
        /// <returns></returns>
        public static void CheckIsNullOrEmptyThrowException( T t)
        {
            if (t == null)
            {
                throw new Framework.Exceptions.BaiTuCoreException("对象为Null");
            }
            if (t is string)
            {
                if (string.IsNullOrEmpty(t as string))
                {
                    throw new Framework.Exceptions.BaiTuCoreException("对象为Empty");
                }
            }
        }
        /// <summary>
        /// 判断是否为Null或Empty 其中Empty仅仅适用于string类型
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static bool CheckIsNullOrEmpty( T t)
        {
            bool flag = false;
            if (t == null)
            {
                flag = true;
            }
            if (t is string)
            {
                if (string.IsNullOrEmpty((t as string)))
                {
                    flag = true;
                }
            }
            return flag;
        }
    }
}
